package at.fhv.androideightpuzzle.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import at.fhv.androideightpuzzle.R;
import at.fhv.androideightpuzzle.application.MultiPlayerClientController;
import at.fhv.androideightpuzzle.application.MultiPlayerHostController;

public class MainActivity extends Activity implements OnClickListener{
	
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		TextView tv = new TextView(this);
		tv.setText("Hello, EightPuzzle Player!");
		setContentView(at.fhv.androideightpuzzle.R.layout.main);
		Button buttonStartSinglePlayer = (Button)findViewById(R.id.btnStartSingle);
		buttonStartSinglePlayer.setOnClickListener(this);
		
		Button buttonStartServer =(Button)findViewById(R.id.btnServer);
		buttonStartServer.setOnClickListener(this);
		
		Button buttonStartClient = (Button)findViewById(R.id.btnClient);
		buttonStartClient.setOnClickListener(this);
		
		if(savedInstanceState != null) {
			((Button)findViewById(at.fhv.androideightpuzzle.R.id.btnStartSingle)).setText("Hallo");
		}
	}
	
	protected void onStart(){
		super.onStart();
	}
	
	protected void onResume(){
		super.onResume();
		
		MultiPlayerClientController.disposeInstance();
		MultiPlayerHostController.disposeInstance();
	}

	public void onClick(View view) {
		
		if(view instanceof Button) {
			Intent intent = null;
			
			if(view.getId() == R.id.btnClient) {
				intent = new Intent(this, LoginActivity.class);
			} else if(view.getId() == R.id.btnStartSingle) {
				intent = new Intent(this, SelectPuzzleActivity.class);
			}else if(view.getId()==R.id.btnServer){
				intent=new Intent(this,AcceptClientsActivity.class);
			}
			
			startActivity(intent);
		}
		/*
		try{
			Intent intent = null;
			
			
			if(view.getId() == R.id.puzzle_list) {
				intent = new Intent(this, SelectPuzzleActivity.class);
				startActivity(intent);
			}
			if(view.getId() == R.id.)
			
		}catch(Exception exc){
			Log.e("MainActivity",exc.getLocalizedMessage());
		}
		**/
	}
}
